home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / dev / fsystem-1.2 / fio.txt < prev    next >
Encoding:
Text File  |  1994-05-22  |  14.4 KB  |  525 lines

  1. (* $VER: fio 1.2 (24-Nov-93) Copyright © by Lars Düning *)
  2.  
  3. DEFINITION fio;
  4.  
  5.  ---------------------------------------------------------------------------
  6.   File-IO for Amiga-Oberon.
  7.  
  8.   Copyright © 1991-1993  Lars Düning  -  All rights reserved.
  9.   Permission granted for non-commercial use.
  10.  ---------------------------------------------------------------------------
  11.   CREDIT
  12.     The module evolved from the io standard module of Amiga-Oberon 1.17.1
  13.  ---------------------------------------------------------------------------
  14.  
  15. CONST
  16.  
  17.   StdBufSize * = FSystem.StdBufSize;  default buffer size
  18.  
  19.  
  20. CONST: Open() access modes
  21.  
  22.   newFile * = FSystem.newFile;  excl. access, deletes existing file
  23.   oldFile * = FSystem.oldFile;  shared access, file has to exist
  24.   update  * = FSystem.update;   excl. access, file may exist
  25.  
  26.  
  27. CONST: Open() operation modes
  28.  
  29.   writeOnly * = FSystem.writeOnly;
  30.   readOnly  * = FSystem.readOnly;
  31.   readWrite * = FSystem.readWrite;
  32.  
  33.  
  34. CONST: File.status, in fact error codes
  35.  
  36.   ok        * = FSystem.ok;         no error
  37.   eof       * = FSystem.eof;        reached end of file
  38.   readerr   * = FSystem.readerr;    unspecified read error, ask Dos
  39.   writeerr  * = FSystem.writeerr;   unspecified write error, ask Dos
  40.   onlyread  * = FSystem.onlyread;   file is read only
  41.   onlywrite * = FSystem.onlywrite;  file is write only
  42.   toofar    * = FSystem.toofar;     seeked beyond the file's ends
  43.   outofmem  * = FSystem.outofmem;   ran out of memory
  44.   cantopen  * = FSystem.cantopen;   couldn't open file
  45.   cantlock  * = FSystem.cantlock;   couldn't lock file
  46.  
  47.  
  48. TYPE
  49.  
  50.   FilePtr * = FSystem.FilePtr;
  51.   File    * = FSystem.File;
  52.  
  53.  
  54. VAR: stdio of the process initializing the modules
  55.  
  56.   stdin   * : Dos.FileHandlePtr;  starting process's standard input
  57.   stdout  * : Dos.FileHandlePtr;  starting process's standard outout
  58.   stderr  * : Dos.FileHandlePtr;  starting process's standard error output
  59.  
  60.  
  61. PROCEDURE Use * (VAR    file: File
  62.                 ;       name: ARRAY OF CHAR
  63.                 ;    accMode: INTEGER
  64.                 ;    opMode : INTEGER
  65.                 ;    bufsize: LONGINT
  66.                 ): BOOLEAN;
  67.  
  68.   Open a file according to access and operation mode.
  69.  
  70.   Arguments:
  71.     file: the empty(!) File structure to fill in.
  72.     name: the name of the file to open (will be copied into file).
  73.     accMode: the access mode to use.
  74.     opMode : the operation mode to use.
  75.     bufSize: size of the buffer to allocate, must be at least 1.
  76.  
  77.   Result:
  78.     TRUE on success, else FALSE with file.status denoting the error.
  79.  
  80.   A bufsize of 1 will result in unbuffered io.
  81.  
  82.  
  83. PROCEDURE open * (VAR    file: File
  84.                  ;       name: ARRAY OF CHAR
  85.                  ;    accMode: INTEGER
  86.                  ): BOOLEAN;
  87.  
  88.   Open a file for read/write with a default sized buffer.
  89.  
  90.   Arguments:
  91.     file: the empty(!) File structure to fill in.
  92.     name: the name of the file to open (will be copied into file).
  93.     accMode: the access mode to use.
  94.  
  95.   Result:
  96.     TRUE on success, else FALSE with file.status denoting the error.
  97.  
  98.   The allocated buffer will be of StdBufSize.
  99.   The file will be opened for reading and writing.
  100.  
  101.  
  102. PROCEDURE close * (VAR file: File);
  103. PROCEDURE Close * (VAR file: File): BOOLEAN;
  104.  
  105.   Close the file.
  106.  
  107.   Arguments:
  108.     file: the file to close.
  109.  
  110.   Result:
  111.     TRUE on success, else FALSE with file.status denoting the error.
  112.  
  113.   Before closing, all changed data is written out using FlushBuf().
  114.  
  115.  
  116. PROCEDURE StdIn * () : Dos.FileHandlePtr;
  117.  
  118.   The current processes standard input.
  119.  
  120.   Result:
  121.     The FileHandle of standard input or NIL;
  122.  
  123.   Don't call this function for simple tasks!
  124.  
  125.  
  126. PROCEDURE StdOut * () : Dos.FileHandlePtr;
  127.  
  128.   The current processes standard output.
  129.  
  130.   Result:
  131.     The FileHandle of standard output or NIL;
  132.  
  133.   Don't call this function for simple tasks!
  134.  
  135.  
  136. PROCEDURE StdErr * () : Dos.FileHandlePtr;
  137.  
  138.   The current processes standard error output.
  139.  
  140.   Result:
  141.     The FileHandle of standard error output or NIL;
  142.  
  143.   Don't call this function for simple tasks!
  144.   For OS < 2.0, stderr is stdout.
  145.  
  146. PROCEDURE Length * (str: ARRAY OF CHAR): INTEGER;
  147.  
  148.   Determine the length of a string.
  149.  
  150.   Arguments:
  151.     str: the string to check.
  152.  
  153.   Result:
  154.     The strings length.
  155.  
  156.   The replication of this function here (it belongs to Strings) shows
  157.   clearly the need for INLINE PROCEDUREs.
  158.  
  159.  
  160. PROCEDURE write * (VAR out : File; ch: CHAR);
  161. PROCEDURE Write * (VAR out : File; ch: CHAR) : BOOLEAN;
  162.  
  163.   Write a character into a file.
  164.  
  165.   Arguments:
  166.     ch : the character to write.
  167.     out: the file to write into.
  168.  
  169.   Result:
  170.     TRUE on success, else FALSE with out.status denoting the error.
  171.  
  172.  
  173. PROCEDURE writeLn * (VAR out : File);
  174. PROCEDURE WriteLn * (VAR out : File) : BOOLEAN;
  175.  
  176.   Write a Newline into a file.
  177.  
  178.   Arguments:
  179.     out: the file to write into.
  180.  
  181.   Result:
  182.     TRUE on success, else FALSE with out.status denoting the error.
  183.  
  184.  
  185. PROCEDURE writeString * (VAR out: File; str: ARRAY OF CHAR);
  186. PROCEDURE WriteString * (VAR out: File; str: ARRAY OF CHAR) : BOOLEAN;
  187.  
  188.   Write a string into a file.
  189.  
  190.   Arguments:
  191.     out: the file to write into.
  192.     str: the string to write.
  193.  
  194.   Result:
  195.     TRUE on success, else FALSE with out.status denoting the error.
  196.  
  197.   Newlines are not addeDos.
  198.  
  199.  
  200. PROCEDURE tab * (VAR out : File; n: INTEGER);
  201. PROCEDURE Tab * (VAR out : File; n: INTEGER) : BOOLEAN;
  202.  
  203.   Output spaces into a file.
  204.  
  205.   Arguments:
  206.     out : the file to write to.
  207.     n   : the number of spaces to write.
  208.  
  209.   Result:
  210.     TRUE on success, else FALSE with out.status denoting the error.
  211.  
  212.   The output is linewrapped to 80 chars per line.
  213.  
  214.  
  215. PROCEDURE clear * (VAR out : File);
  216. PROCEDURE Clear * (VAR out : File) : BOOLEAN;
  217.  
  218.   Output a formfeed into a file.
  219.  
  220.   Arguments:
  221.     out : the file to write to.
  222.  
  223.   Result:
  224.     TRUE on success, else FALSE with out.status denoting the error.
  225.  
  226.  
  227. PROCEDURE format * (VAR out : File; VAR str: String; data:LONGINT);
  228. PROCEDURE Format * (VAR out : File; VAR str: String; data:LONGINT) : BOOLEAN;
  229.  
  230.   Output a single formatted item into a file.
  231.  
  232.   Arguments:
  233.     out  : the file to write to.
  234.     str  : the format string.
  235.     data : the item to output.
  236.  
  237.   Result:
  238.     TRUE on success, else FALSE with file.status denoting the error.
  239.  
  240.   %% => %
  241.       links  führ.0   min.max Breite  longdata   dez|hex|string|char
  242.     %  [-]    [0]      [123 [.123] ]     [l]        (d|x|s|c)
  243.  
  244.     Char is always WORD, even when specified as 'l'!
  245.     String adresses are always LONG!
  246.  
  247.   Do NOT generate more than 255 chars.
  248.  
  249.  
  250. PROCEDURE writeInt * (VAR out: File; x: LONGINT; n: INTEGER);
  251. PROCEDURE WriteInt * (VAR out: File; x: LONGINT; n: INTEGER) : BOOLEAN;
  252.  
  253.   Output an integer into a file.
  254.  
  255.   Arguments:
  256.     out  : the file to write to.
  257.     x    : the integer to write.
  258.     n    : the minimal number of characters to write.
  259.  
  260.   Result:
  261.     TRUE on success, else FALSE with out.status denoting the error.
  262.  
  263.   The integer will be leftadjusted.
  264.  
  265.  
  266. PROCEDURE writeHex * (VAR out : File; x: LONGINT; n: INTEGER);
  267. PROCEDURE WriteHex * (VAR out : File; x: LONGINT; n: INTEGER) : BOOLEAN;
  268.  
  269.   Output a hex integer into a file.
  270.  
  271.   Arguments:
  272.     out  : the file to write to.
  273.     x    : the integer to write.
  274.     n    : the minimal number of characters to write.
  275.  
  276.   Result:
  277.     TRUE on success, else FALSE with out.status denoting the error.
  278.  
  279.   The integer will be leftadjusted and written in base-16 with leading zeroes.
  280.  
  281.  
  282. PROCEDURE read * (VAR in : File; VAR ch: CHAR);
  283. PROCEDURE Read * (VAR in : File; VAR ch: CHAR) : BOOLEAN;
  284.  
  285.   Read a character from a file.
  286.  
  287.   Arguments:
  288.     in : the file to read from.
  289.     ch : variable taking the character to read
  290.  
  291.   Result:
  292.     TRUE on success, else FALSE with file.status denoting the error.
  293.     ch: the character read.
  294.  
  295.  
  296. PROCEDURE readString * (VAR in : File; VAR str: ARRAY OF CHAR);
  297. PROCEDURE ReadString * (VAR in : File; VAR str: ARRAY OF CHAR) : BOOLEAN;
  298.  
  299.   Read a string from a file.
  300.  
  301.   Arguments:
  302.     in  : the file to read from.
  303.     str : variable taking the string to read
  304.  
  305.   Result:
  306.     TRUE on success, else FALSE with file.status denoting the error.
  307.     str: the string read.
  308.  
  309.   The function reads until an \0 or \n is encountered (which won't be
  310.   stored), or the buffer is exhausteDos. If possible, the string
  311.   is terminated by \0.
  312.  
  313.  
  314. PROCEDURE readLong * (VAR in : File; VAR x: LONGINT);
  315. PROCEDURE ReadLong * (VAR in : File; VAR x: LONGINT): BOOLEAN;
  316.  
  317.   Read a long integer from a file.
  318.  
  319.   Arguments:
  320.     in : the file to read from.
  321.     x  : variable taking the long integer read
  322.  
  323.   Result:
  324.     TRUE on success, else FALSE with file.status denoting the error.
  325.       If FALSE is returned, but in.status is 'ok', then the read characters
  326.       do not form a legal number.
  327.     x: the long integer read.
  328.  
  329.   Linebreaks after a number aren't read.
  330.   Leading whitespace will be ignored.
  331.  
  332.  
  333. PROCEDURE readInt * (VAR in : File; VAR x: INTEGER);
  334. PROCEDURE ReadInt * (VAR in : File; VAR x: INTEGER): BOOLEAN;
  335.  
  336.   Read an integer from a file.
  337.  
  338.   Arguments:
  339.     in : the file to read from.
  340.     x  : variable taking the integer read
  341.  
  342.   Result:
  343.     TRUE on success, else FALSE with file.status denoting the error.
  344.       If FALSE is returned, but in.status is 'ok', then the read characters
  345.       do not form a legal number.
  346.     x: the integer read.
  347.  
  348.   Linebreaks after a number aren't read.
  349.   Leading whitespace will be ignored.
  350.  
  351.  
  352. PROCEDURE readShort * (VAR in : File; VAR x: SHORTINT);
  353. PROCEDURE ReadShort * (VAR in : File; VAR x: SHORTINT): BOOLEAN;
  354.  
  355.   Read a short integer from a file.
  356.  
  357.   Arguments:
  358.     in : the file to read from.
  359.     x  : variable taking the short integer read
  360.  
  361.   Result:
  362.     TRUE on success, else FALSE with file.status denoting the error.
  363.       If FALSE is returned, but in.status is 'ok', then the read characters
  364.       do not form a legal number.
  365.     x: the short integer read.
  366.  
  367.   Linebreaks after a number aren't reaDos.
  368.   Leading whitespace will be ignoreDos.
  369.  
  370.  
  371. PROCEDURE readHex * (VAR in : File; VAR x: LONGINT);
  372. PROCEDURE ReadHex * (VAR in : File; VAR x: LONGINT): BOOLEAN;
  373.  
  374.   Read a long integer in base-16 notation from a file.
  375.  
  376.   Arguments:
  377.     in : the file to read from.
  378.     x  : variable taking the long integer read
  379.  
  380.   Result:
  381.     TRUE on success, else FALSE with file.status denoting the error.
  382.       If FALSE is returned, but in.status is 'ok', then the read characters
  383.       do not form a legal number.
  384.     x: the long integer read.
  385.  
  386.   Linebreaks after a number aren't reaDos.
  387.   Leading whitespace will be ignoreDos.
  388.  
  389. END fio.
  390.  
  391. (***************************************************************************)
  392.  
  393. (* $VER: fRealIO 1.1 (21-May-94) Copyright © by Lars Düning *)
  394.  
  395. DEFINITION fRealIO;
  396.  
  397.  ---------------------------------------------------------------------------
  398.   File-IO of REAL numbers for Amiga-Oberon.
  399.  
  400.   Copyright © 1991-1994  Lars Düning  -  All rights reserved.
  401.   Permission granted for non-commercial use.
  402.  ---------------------------------------------------------------------------
  403.   CREDIT:
  404.     This module evolved from RealIO of Amiga-Oberon v1.17.1
  405.  ---------------------------------------------------------------------------
  406.  
  407. PROCEDURE ParseReal * ( VAR in : fio.File; VAR str : ARRAY OF CHAR) : BOOLEAN;
  408.  
  409.   Parse a REAL number from a file.
  410.  
  411.   Arguments:
  412.     in  : the file to read from.
  413.     str : buffer taking the number string.
  414.  
  415.   Result:
  416.     TRUE on success, else FALSE with in.status denoting the error.
  417.       If FALSE is returned, but in.status is 'ok', then no correct number
  418.       could be read.
  419.  
  420.   Leading whitespace are ignored, trailing linebreaks are not read.
  421.  
  422.  
  423. PROCEDURE writeReal * ( VAR    f : fio.File
  424.                       ;        r : REAL
  425.                       ;     v, n : INTEGER
  426.                       ;      exp : BOOLEAN
  427.                       );
  428. PROCEDURE WriteReal * ( VAR    f : fio.File
  429.                       ;        r : REAL
  430.                       ;     v, n : INTEGER
  431.                       ;      exp : BOOLEAN
  432.                       ): BOOLEAN;
  433.  
  434.   Write a REAL number into a file.
  435.  
  436.   Arguments:
  437.     f  : the file to write to.
  438.     r  : the number to write.
  439.     v  : number of digits in front of the '.'
  440.     n  : number of digits after the '.'
  441.     exp: if TRUE, the 'E' notation is used when appropriate.
  442.  
  443.   Result:
  444.     TRUE on success, else FALSE with out.status denoting the error.
  445.       If FALSE is returned, but out.status is 'ok', then the number is
  446.       larger than the allowed number of digits.
  447.  
  448.  
  449. PROCEDURE readReal * (VAR f : fio.File; VAR r: REAL);
  450. PROCEDURE ReadReal * (VAR f : fio.File; VAR r: REAL): BOOLEAN;
  451.  
  452.   Read a REAL number from a file.
  453.  
  454.   Arguments:
  455.     f  : the file to read from.
  456.     r  : variable to take the number read.
  457.  
  458.   Result:
  459.     TRUE on success, else FALSE with out.status denoting the error.
  460.       If FALSE is returned, but out.status is 'ok', then no correct number
  461.       could be read.
  462.     r: the number read.
  463.  
  464. END fRealIO.
  465.  
  466. (***************************************************************************)
  467.  
  468. (* $VER: fLRealIO 1.1 (21-May-94) Copyright © by Lars Düning *)
  469.  
  470. DEFINITION fLRealIO;
  471.  
  472.  ---------------------------------------------------------------------------
  473.   File-IO of LONGREAL numbers for Amiga-Oberon.
  474.  
  475.   Copyright © 1991-1994  Lars Düning  -  All rights reserved.
  476.   Permission granted for non-commercial use.
  477.  ---------------------------------------------------------------------------
  478.   CREDIT:
  479.     This module evolved from RealIO of Amiga-Oberon v1.17.1
  480.  ---------------------------------------------------------------------------
  481.  
  482. PROCEDURE writeReal * ( VAR    f : fio.File
  483.                       ;        r : LONGREAL
  484.                       ;     v, n : INTEGER
  485.                       ;      exp : BOOLEAN
  486.                       );
  487. PROCEDURE WriteReal * ( VAR    f : fio.File
  488.                       ;        r : LONGREAL
  489.                       ;     v, n : INTEGER
  490.                       ;      exp : BOOLEAN
  491.                       ): BOOLEAN;
  492.  
  493.   Write a REAL number into a file.
  494.  
  495.   Arguments:
  496.     f  : the file to write to.
  497.     r  : the number to write.
  498.     v  : number of digits in front of the '.'
  499.     n  : number of digits after the '.'
  500.     exp: if TRUE, the 'E' notation is used when appropriate.
  501.  
  502.   Result:
  503.     TRUE on success, else FALSE with out.status denoting the error.
  504.       If FALSE is returned, but out.status is 'ok', then the number is
  505.       larger than the allowed number of digits.
  506.  
  507.  
  508. PROCEDURE readReal * (VAR f : fio.File; VAR r: LONGREAL);
  509. PROCEDURE ReadReal * (VAR f : fio.File; VAR r: LONGREAL): BOOLEAN;
  510.  
  511.   Read a REAL number from a file.
  512.  
  513.   Arguments:
  514.     f  : the file to read from.
  515.     r  : variable to take the number read.
  516.  
  517.   Result:
  518.     TRUE on success, else FALSE with out.status denoting the error.
  519.       If FALSE is returned, but out.status is 'ok', then no correct number
  520.       could be read.
  521.     r: the number read.
  522.  
  523. END fLRealIO.
  524.  
  525.